﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace JumpstartApp.Contracts
{
    using JumpstartApp.Helpers;

    public sealed partial class Settings : UserControl, INotifyPropertyChanged
    {
        public Settings()
        {
            this.InitializeComponent();
            this.DataContext = this;
        }

        public static readonly string DefaultColor = Windows.UI.Colors.Green.ToString();
        public const string PrimaryColor = "Setting.PrimaryColor";
        private void GridView_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            var _Color = ((e.ClickedItem as Windows.UI.Xaml.Shapes.Rectangle).Fill as SolidColorBrush).Color;
            StorageHelper.SetSetting(PrimaryColor, _Color.ToString());
            MyGrid.Background = (e.ClickedItem as Windows.UI.Xaml.Shapes.Rectangle).Fill as SolidColorBrush;
            Views.Splash.SetupTheme();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Windows.UI.ApplicationSettings.SettingsPane.Show();
        }

        private static readonly string ShowSilhouetteKey = "Setting.ShowSilhouette";
        public bool ShowSilhouetteSetting
        {
            get { return ShowSilhouette; }
            set { ShowSilhouette = value; }
        }
        public static bool ShowSilhouette
        {
            get { return StorageHelper.GetSetting(ShowSilhouetteKey, false); }
            set { StorageHelper.SetSetting(ShowSilhouetteKey, value); }
        }

        private const string LimiteDataKey = "Setting.LimiteData";
        public bool LimiteDataSetting
        {
            get { return LimiteData; }
            set { LimiteData = value; }
        }
        public static bool LimiteData
        {
            get { return StorageHelper.GetSetting(LimiteDataKey, true); }
            set { StorageHelper.SetSetting(LimiteDataKey, value); }
        }

        private const string AllowLoginKey = "Setting.AllowLoginIn";
        public bool AllowLoginSetting
        {
            get { return AllowLogin; }
            set { AllowLogin = value; }
        }
        public static bool AllowLogin
        {
            get { return StorageHelper.GetSetting(AllowLoginKey, false); }
            set { StorageHelper.SetSetting(AllowLoginKey, value); }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        void SetProperty<T>(ref T storage, T value, [System.Runtime.CompilerServices.CallerMemberName] String propertyName = null)
        {
            if (!object.Equals(storage, value))
            {
                storage = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        void RaisePropertyChanged([System.Runtime.CompilerServices.CallerMemberName] String propertyName = null)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
